package com.helloworld.demo.sync;

import org.openjdk.jol.info.ClassLayout;

public class ObjectTest {
    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(5000);
        Object o = new Object();
        //o.hashCode();

        //查看对象的内部结构，后面存低位是小端存储，后面存高位是大端存储
        System.out.println(ClassLayout.parseInstance(o).toPrintable());

        /*new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (o){
                    System.out.println(ClassLayout.parseInstance(o).toPrintable());
                }
            }
        },"Thread-1").start();*/

        /*new Thread(new Runnable() {
            @Override
            public void run() {
                //o.hashCode();
                synchronized (ObjectTest.class){
                    o.hashCode();
                    System.out.println(ClassLayout.parseInstance(ObjectTest.class).toPrintable());
                    System.out.println(ClassLayout.parseInstance(o).toPrintable());
                }
            }
        },"Thread-1").start();*/


        /*new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (o){
                    try {
                        //o.wait(100);
                        o.notify();
                        System.out.println(ClassLayout.parseInstance(o).toPrintable());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        },"Thread-2").start();*/

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (o){
                    System.out.println(ClassLayout.parseInstance(o).toPrintable());
                }
            }
        },"Thread-1").start();


        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (o){
                    System.out.println(ClassLayout.parseInstance(o).toPrintable());
                }
            }
        },"Thread-2").start();





    }
}
